<?php
/**
 * Get all elements of a given page
 */
 
// Return json encoded data
header ('Content-type: application/json');

session_start();
require_once '../core/db.php';
//TO DO: Check if private or not/belong to user or not

// Return elements belonging to page
$sql = 'SELECT elementId as id, elementTitle as title, elementText as content, showDate, DATE_FORMAT(`elementCreated`, "%a %e/%c-%Y (%k:%i)") as created, DATE_FORMAT(`elementUpdated`, "%a %e/%c-%Y (%k:%i)") as edited, isCarousel FROM siteElement WHERE pageId=? order by elementIndex ASC, elementCreated DESC';
$sth = $db->prepare ($sql);
$sth->execute (array ($_POST['id']));
die (json_encode  ($sth->fetchAll (PDO::FETCH_ASSOC)));
?>